package com.apkplugthemedemo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.apkplug.Bundle.ThemeControl;
import org.apkplug.app.FrameworkFactory;
import org.apkplug.app.FrameworkInstance;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

import android.app.Application;
import android.util.DisplayMetrics;
import android.view.WindowManager;

public class ProxyApplication extends Application {
	private FrameworkInstance frame=null;

	public FrameworkInstance getFrame() {
		return frame;
	}

	public void onCreate() {   
		 super.onCreate(); 
		 try
	        {
				frame=FrameworkFactory.getInstance().start(null,this,new MyProperty(this.getApplicationContext()));
				
	        }
	        catch (Exception ex)
	        {
	            System.err.println("Could not create : " + ex);
	            ex.printStackTrace();
	            int nPid = android.os.Process.myPid();
				android.os.Process.killProcess(nPid);
	        }
	}
	public void setTheme1(long id) throws Exception{
		BundleContext mcontext=frame.getSystemBundleContext();
		ServiceReference reference=mcontext.getServiceReference(ThemeControl.class.getName());
    	if(null!=reference){
    		ThemeControl service=(ThemeControl) mcontext.getService(reference);
    		if(service!=null){
    			service.setTheme(mcontext,id);
    		}
    	mcontext.ungetService(reference);
    	}
	}	
}
